<?php
/**
 *  set user:userid:1:username zhangsan
 *  set user:userid:1:password 111111
 *  <登录使用>
 *  set user:username:zhangsan:userid 1
 */
include "header.php";
include('./lib/func.php');
include "./lib/config.php";


if (isLogin() != false){
    header("location:home.php");
    exit;
}


$username = getPost('username');
$pwd = getPost('password');
$pwd2 = getPost('password2');

if (!$username || !$pwd || !$pwd2 ){
    showError('请输入完整注册信息');
}

if ($pwd !== $pwd2){
    showError('两次输入密码不一致');
}

$redis = connentRedis(Config::REDISHOST, Config::PORT);
$name = $redis->get('user:username:'. $username . ':userid');
if ($name){
    showError('该用户名已被注册');
}

$userid = $redis->incr('global:userid');

$redis->set('user:userid:'. $userid. ':username', $username);
$redis->set('user:userid:'. $userid. ':password', $pwd);

$redis->set('user:username:'. $username. ':userid', $userid);

//使用链表储存用户[获取最新50个用户]
$redis->lPush('newuserlink', $userid);
$redis->lTrim('newuserlink', 0, 49);




header("location:login.php");





include "footer.php";
